package sort

import "fmt"

func IsSorted(data []int) bool {
	for i := 0; i < len(data)-1; i++ {
		if data[i] > data[i+1] {
			return false
		}
	}
	return true
}
func exch(data []int, i, j int) []int {
	tmp := data[i]
	data[i] = data[j]
	data[j] = tmp
	return data
}
func SelectionSort(data []int) {
	for i := 0; i < len(data); i++ {
		// find the smallest
		min := i
		for j := i; j < len(data); j++ {
			if data[j] < data[min] {
				min = j
			}
		}
		exch(data, i, min)
	}
}

func InsertionSort(data []int) {
	for i := 1; i < len(data); i++ {
		fmt.Println("----", data[i])
		for j := i - 1; j >= 0 && data[j] > data[j+1]; j-- {
			data = exch(data, j, j+1)
		}
	}
}
